<?php
/**
 * SMemberAddressModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/26
 * Time: 22:34
 */
namespace app\common\auto_curd\php_system\model;

use think\Db;

class SMemberAddressModel
{
    /**
     * ID
     */
    protected $id = '';
    public function getId()
    {
        return $this->id;
    }
    public function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * 所在省
     */
    protected $province = '0';
    public function getProvince()
    {
        return $this->province;
    }
    public function setProvince($province)
    {
        $this->province = $province;
    }
    
    /**
     * 所在市
     */
    protected $city = '0';
    public function getCity()
    {
        return $this->city;
    }
    public function setCity($city)
    {
        $this->city = $city;
    }
    
    /**
     * 所在县/区
     */
    protected $county = '0';
    public function getCounty()
    {
        return $this->county;
    }
    public function setCounty($county)
    {
        $this->county = $county;
    }
    
    /**
     * 会员ID
     */
    protected $member_id = '0';
    public function getMemberId()
    {
        return $this->member_id;
    }
    public function setMemberId($member_id)
    {
        $this->member_id = $member_id;
    }
    
    /**
     * 创建时间
     */
    protected $create_ts = '0';
    public function getCreateTs()
    {
        return $this->create_ts;
    }
    public function setCreateTs($create_ts)
    {
        $this->create_ts = $create_ts;
    }
    
    /**
     * 修改时间
     */
    protected $update_ts = '0';
    public function getUpdateTs()
    {
        return $this->update_ts;
    }
    public function setUpdateTs($update_ts)
    {
        $this->update_ts = $update_ts;
    }
    
    /**
     * 经度
     */
    protected $lng = '0.0000000000';
    public function getLng()
    {
        return $this->lng;
    }
    public function setLng($lng)
    {
        $this->lng = $lng;
    }
    
    /**
     * 纬度
     */
    protected $lat = '0.0000000000';
    public function getLat()
    {
        return $this->lat;
    }
    public function setLat($lat)
    {
        $this->lat = $lat;
    }
    
    /**
     * 电话
     */
    protected $tel = '';
    public function getTel()
    {
        return $this->tel;
    }
    public function setTel($tel)
    {
        $this->tel = $tel;
    }
    
    /**
     * 别名
     */
    protected $alias = '';
    public function getAlias()
    {
        return $this->alias;
    }
    public function setAlias($alias)
    {
        $this->alias = $alias;
    }
    
    /**
     * 姓名
     */
    protected $name = '';
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
    
    /**
     * 详细地址
     */
    protected $address = '';
    public function getAddress()
    {
        return $this->address;
    }
    public function setAddress($address)
    {
        $this->address = $address;
    }
    
    /**
     * 是否默认地址（0否, 1是）
     */
    protected $is_default = '0';
    public function getIsDefault()
    {
        return $this->is_default;
    }
    public function setIsDefault($is_default)
    {
        $this->is_default = $is_default;
    }
    
    /**
     * 是否删除（0否，1删除时间戳）
     */
    protected $is_delete_time = '0';
    public function getIsDeleteTime()
    {
        return $this->is_delete_time;
    }
    public function setIsDeleteTime($is_delete_time)
    {
        $this->is_delete_time = $is_delete_time;
    }
    
    /**
     * constructor.
     * @param array $data
     */
    public function __construct($data=[])
    {

        // ID
        if(isset($data['id']))
        {
            $this->id = $data['id'];
        }

        // 所在省
        if(isset($data['province']))
        {
            $this->province = $data['province'];
        }

        // 所在市
        if(isset($data['city']))
        {
            $this->city = $data['city'];
        }

        // 所在县/区
        if(isset($data['county']))
        {
            $this->county = $data['county'];
        }

        // 会员ID
        if(isset($data['member_id']))
        {
            $this->member_id = $data['member_id'];
        }

        // 创建时间
        if(isset($data['create_ts']))
        {
            $this->create_ts = $data['create_ts'];
        }

        // 修改时间
        if(isset($data['update_ts']))
        {
            $this->update_ts = $data['update_ts'];
        }

        // 经度
        if(isset($data['lng']))
        {
            $this->lng = $data['lng'];
        }

        // 纬度
        if(isset($data['lat']))
        {
            $this->lat = $data['lat'];
        }

        // 电话
        if(isset($data['tel']))
        {
            $this->tel = $data['tel'];
        }

        // 别名
        if(isset($data['alias']))
        {
            $this->alias = $data['alias'];
        }

        // 姓名
        if(isset($data['name']))
        {
            $this->name = $data['name'];
        }

        // 详细地址
        if(isset($data['address']))
        {
            $this->address = $data['address'];
        }

        // 是否默认地址（0否, 1是）
        if(isset($data['is_default']))
        {
            $this->is_default = $data['is_default'];
        }

        // 是否删除（0否，1删除时间戳）
        if(isset($data['is_delete_time']))
        {
            $this->is_delete_time = $data['is_delete_time'];
        }

    }
    
    /**
     * 获取分页信息
     * @param $where
     * @param array $extend
     * @return \think\Paginator
     */
    static public function paginate($where,$extend=[])
    {
        $handler = Db::table('s_member_address');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->paginate();
    }
    
    /**
     * 添加|修改
     * @param $flag
     * @param $data
     * @param array $extend
     * @return int|string
     */
    static public function save($flag,$data,$extend=[])
    {
        if(empty($flag))
        {
            // 添加
            $data['create_ts'] = time();
            return Db::table('s_member_address')
                ->insertGetId($data);
        }
        else
        {
            // 编辑
            $data['update_ts'] = time();
            return Db::table('s_member_address')
                ->where('id',$flag)
                ->update($data);
        }
    }
    
    /**
     * 获取详情
     * @param $where
     * @param array $extend
     * @return array|false|null|\PDOStatement|string|\think\Model
     */
    static public function get($where,$extend=[])
    {
        $handler = Db::table('s_member_address');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->find();
    }
    
    /**
     * 删除
     * @param $flag
     * @param array $extend
     * @return int
     */
    static public function delete($flag,$extend=[])
    {
        return Db::table('s_member_address')
            ->where('id',$flag)
            ->delete();
    }
}